package com.ruoyi.module.app.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.common.page.PageInfo;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.module.app.domain.ShAd;
import lombok.extern.slf4j.Slf4j;
import com.ruoyi.module.app.service.IShAdService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.Result;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 广告Controller
 *
 * @author mars
 * @date 2022-09-16
 */
@Slf4j
@AllArgsConstructor
@RestController
@RequestMapping("/app/ad" )
public class ShAdController extends BaseController {

    private final IShAdService iShAdService;

    /**
     * 查询广告列表
     */
    @PreAuthorize("@ss.hasPermi('app:ad:list')")
    @GetMapping("/list")
    public PageInfo list(ShAd shAd) {
        return iShAdService.findPageBySpec(shAd);
    }

    /**
     * 获取广告详细信息
     */
    @PreAuthorize("@ss.hasPermi('app:ad:query')" )
    @GetMapping(value = "/query/{id}" )
    public Result getInfo(@PathVariable("id" ) Integer id) {
        return Result.success(iShAdService.getById(id));
    }

    /**
     * 新增广告
     */
    @PreAuthorize("@ss.hasPermi('app:ad:add')" )
    @Log(title = "广告" , businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public Result add(@RequestBody ShAd shAd) {
        return Result.success("新增成功",iShAdService.add(shAd));
    }

    /**
     * 修改广告
     */
    @PreAuthorize("@ss.hasPermi('app:ad:edit')" )
    @Log(title = "广告" , businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public Result edit(@RequestBody ShAd shAd) {
        return toAjax(iShAdService.update(shAd) ? 1 : 0);
    }

    /**
     * 删除广告
     */
    @PreAuthorize("@ss.hasPermi('app:ad:remove')" )
    @Log(title = "广告" , businessType = BusinessType.DELETE)
    @DeleteMapping("/remove/{ids}" )
    public Result remove(@PathVariable Integer[] ids) {
        return toAjax(iShAdService.deleteBatch(Arrays.asList(ids)) ? 1 : 0);
    }

    /**
     * 导出广告列表
     */
    @PreAuthorize("@ss.hasPermi('app:ad:export')" )
    @Log(title = "广告" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public Result export(ShAd shAd) {
        LambdaQueryWrapper<ShAd> lqw = new LambdaQueryWrapper<ShAd>(shAd);
        List<ShAd> list = iShAdService.list(lqw);
        ExcelUtil<ShAd> util = new ExcelUtil<ShAd>(ShAd. class);
        return util.exportExcel(list, "ad" );
    }
}
